import { IParamParsingDto, IParamResultVo } from '../dto/expression.ts';
import { ExpressionEngine } from '../model/expression-engine.ts';

// TODO 通过装饰器声明path和method
export async function parseExpression(
  { params, expression, resultType }: IParamParsingDto,
): Promise<IParamResultVo> {
  const engine = new ExpressionEngine(params || [], expression, resultType);

  return {
    type: resultType,
    value: await engine.eval(),
  };
}
